import request from "@/utils/request";
import {PriorityModel} from "@/model/PriorityModel";
import {PagingModel} from "@/model/PagingModel";

export default class PriorityApi {

    /**
     * 查询当前系统设备列表
     */
    public static list(): Promise<PriorityModel[]> {
        return new Promise((resolve, reject) => {
            request({
                url: '/queue/priority/list',
                method: 'get'
            }).then((res: any) => {
                if (res.code === 200) {
                    const data = res.rows ? res.rows.map(item => new PriorityModel().deserialize(item)) : []
                    resolve(data)
                } else {
                    reject(res);
                }
            })
        })
    }

    /**
     * 创建
     * @param priority
     */
    public static save(priority: PriorityModel): Promise<PriorityModel> {
        return new Promise((resolve, reject) => {
            request({
                url: `/queue/priority/save`,
                method: 'POST',
                data: priority
            }).then((res: any) => {
                if (res.code === 200) {
                    resolve(new PriorityModel().deserialize(res.data))
                } else {
                    reject(res);
                }
            }, () => reject())
        })
    }

    /**
     * 更新字典
     * @param id
     * @param priority
     */
    public static update(id:string, priority: PriorityModel): Promise<PriorityModel> {
        return new Promise((resolve, reject) => {
            request({
                url: `/queue/priority/${id}`,
                method: 'PUT',
                data: priority
            }).then((res: any) => {
                if (res.code === 200) {
                    resolve(new PriorityModel().deserialize(res.data))
                } else {
                    reject(res);
                }
            }, () => reject())
        })
    }

    public static delete(id:string): Promise<boolean> {
        return new Promise<boolean>((resolve, reject) => {
            request({
                url: `/queue/priority/${id}`,
                method: 'DELETE',
            }).then((res: any) => {
                if (res) {
                    resolve(res)
                } else {
                    reject(res);
                }
            }, () => reject())
        })
    }

}